<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="活动名称" prop="promotionName">
        <el-input v-model="queryParams.promotionName" placeholder="请输入活动名称" clearable
          style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="获取方式" prop="getType">
        <el-select v-model="queryParams.getType" placeholder="获取方式" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.coupon_get_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="couponType">
        <el-select v-model="queryParams.couponType" placeholder="类型" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.coupon_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.paramMap.status" placeholder="活动状态" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.goods_promotion_status" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="活动日期">
        <el-date-picker v-model="promotionDateRange" style="width: 220px" value-format="yyyy-MM-dd" clearable
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建日期">
        <el-date-picker v-model="dateRange" style="width: 220px" value-format="yyyy-MM-dd" clearable
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['store:promotion:coupon:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
          @click="handleUpdate" v-hasPermi="['store:promotion:coupon:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
          @click="handleDelete" v-hasPermi="['store:promotion:coupon:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['store:promotion:coupon:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['store:promotion:coupon:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns">
      </right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="goodsSkuList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="columns[0].label" :prop="columns[0].prop" :width="columns[0].width"
        align="center" v-if="columns[0].visible" />
      <el-table-column :label="columns[1].label" :prop="columns[1].prop" :width="columns[1].width"
        align="center" v-if="columns[1].visible" />
      <el-table-column :label="columns[2].label" :prop="columns[2].prop" :width="columns[2].width"
        align="center" v-if="columns[2].visible" />
      <el-table-column :label="columns[3].label" :prop="columns[3].prop" :width="columns[3].width"
        align="center" v-if="columns[3].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.coupon_get_type" :value="scope.row.getType" />
        </template>
      </el-table-column>
      <el-table-column :label="columns[4].label" :prop="columns[4].prop" :width="columns[4].width"
        align="center" v-if="columns[4].visible" />
      <el-table-column :label="columns[5].label" :prop="columns[5].prop" :width="columns[5].width"
        align="center" v-if="columns[5].visible" />
      <el-table-column :label="columns[6].label" :prop="columns[6].prop" :width="columns[6].width"
        align="center" v-if="columns[6].visible" />
      <el-table-column :label="columns[7].label" :prop="columns[7].prop" :width="columns[7].width"
        align="center" v-if="columns[7].visible">
      </el-table-column>
      <el-table-column :label="columns[8].label" :prop="columns[8].prop" :width="columns[8].width"
        align="center" v-if="columns[8].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.coupon_type" :value="scope.row.couponType" />
        </template>
      </el-table-column>
      <el-table-column :label="columns[9].label" :prop="columns[9].prop" :width="columns[9].width"
        align="center" v-if="columns[9].visible" />
      <el-table-column :label="columns[10].label" :prop="columns[10].prop" :width="columns[10].width"
        align="center" v-if="columns[10].visible" />
      <el-table-column :label="columns[11].label" :prop="columns[11].prop"
        :width="columns[11].width" align="center" v-if="columns[11].visible" />
      <el-table-column :label="columns[12].label" :prop="columns[12].prop"
        :width="columns[12].width" align="center" v-if="columns[12].visible" />
      <el-table-column :label="columns[13].label" :prop="columns[13].prop"
        :width="columns[13].width" width="250" align="center" :show-overflow-tooltip="true"
        v-if="columns[13].visible" />
      <el-table-column :label="columns[14].label" :prop="columns[14].prop"
        :width="columns[14].width" align="center" :show-overflow-tooltip="true"
        v-if="columns[14].visible" />
      <el-table-column :label="columns[15].label" :prop="columns[15].prop" :show-overflow-tooltip="true"
        :width="columns[15].width" align="center" v-if="columns[15].visible" />
      <el-table-column :label="columns[16].label" :prop="columns[16].prop" :show-overflow-tooltip="true"
        :width="columns[16].width" align="center" v-if="columns[16].visible" />
      <el-table-column :label="columns[17].label" :prop="columns[17].prop" :show-overflow-tooltip="true"
        :width="columns[17].width" align="center" v-if="columns[17].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.promotion_scope_type" :value="scope.row.scopeType" />
        </template>
      </el-table-column>
      <el-table-column :label="columns[18].label" :prop="columns[18].prop" :show-overflow-tooltip="true"
        :width="columns[18].width" align="center" v-if="columns[18].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.promotion_promotion_status"
            :value="scope.row.promotionStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="toVoid(scope.row)"
            v-hasPermi="['store:promotion:coupon:cancel']">作废</el-button>

          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleUpdate" icon="el-icon-edit"
                v-hasPermi="['store:promotion:coupon:edit']">修改</el-dropdown-item>
              <el-dropdown-item command="handleImportGoods" icon="el-icon-circle-check"
                v-if="scope.row.scopeType === 'PORTION_GOODS'"
                v-hasPermi="['store:promotion:coupon:goods:import']">导入促销商品</el-dropdown-item>
              <el-dropdown-item command="handleSeeSalesGoods" icon="el-icon-grape"
                v-if="scope.row.scopeType === 'PORTION_GOODS'"
                v-hasPermi="['store:promotion:promotion:goods:page']">查看促销商品</el-dropdown-item>
              <el-dropdown-item command="handleImportExcludeGoods" icon="el-icon-delete"
                v-if="scope.row.scopeType != 'PORTION_GOODS'"
                v-hasPermi="['store:promotion:coupon:exclude:goods:import']">屏蔽商品导入</el-dropdown-item>
              <el-dropdown-item command="handleExcludeGoods" icon="el-icon-truck"
                v-if="scope.row.scopeType != 'PORTION_GOODS'"
                v-hasPermi="['store:promotion:coupon:exclude:sku:page']">查看屏蔽的商品</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 创建或修改优惠券对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="title" :visible.sync="open" width="750">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px" :inline="true"
        class="demo-form-inline">
        <el-form-item label="活动名称" prop="promotionName">
          <el-input v-model="form.promotionName" placeholder="请输入活动名称" style="width:300px" />
        </el-form-item>
        <el-form-item label="优惠券名称" prop="couponName" class="couponName">
          <el-input v-model="form.couponName" placeholder="请输入优惠券名称" style="width:300px" id="ipt" />
        </el-form-item>
        <el-form-item label="获取方式" prop="getType">
          <el-radio-group v-model="form.getType" style="width:300px">
            <el-radio v-for="dict in dict.type.coupon_get_type" :key="dict.value"
              :label="dict.value">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="促销范围" prop="scopeType">
          <el-radio-group v-model="form.scopeType">
            <el-radio v-for="dict in dict.type.promotion_scope_type" :key="dict.value"
              :label="dict.value">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime" class="start">
          <el-date-picker v-model="form.startTime" value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime" placeholder="选择日期时间" :show-overflow-tooltip="true" style="width:300px"
            :disabled="disabledStstus"> </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker v-model="form.endTime" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
            placeholder="选择日期时间" :show-overflow-tooltip="true" style="width:300px"
            :disabled="disabledStstus"> </el-date-picker>
        </el-form-item>
        <el-form-item label="消费门槛数量" prop="consumeQuantity">

          <el-input-number v-model="form.consumeQuantity" placeholder="请输入消费门槛数量"
            controls-position="right" :disabled="form.consumeThreshold !== 0"
            @blur=" (e, name) => {blurNumber(e, 'consumeQuantity')} " style="width:300px"
            v-if="!disabledStstus" />

          <el-input :value="form.consumeQuantity" placeholder="请输入消费门槛数量" controls-position="right"
            style="width:300px" v-if="disabledStstus" :disabled="disabledStstus" />
        </el-form-item>
        <el-form-item label="消费门槛金额" prop="consumeThreshold">
          <el-input-number v-model="form.consumeThreshold" placeholder="请输入消费门槛金额"
            controls-position="right" :disabled="form.consumeQuantity !== 0"
            @blur=" (e, name) => {blurNumber(e, 'consumeThreshold')} " style="width:300px"
            v-if="!disabledStstus" />
          <el-input :value="form.consumeThreshold" placeholder="请输入消费门槛数量" controls-position="right"
            style="width:300px" v-if="disabledStstus" :disabled="disabledStstus" />
        </el-form-item>
        <el-form-item label="领取上限" prop="couponLimitNum">
          <el-input-number v-model="form.couponLimitNum" placeholder="请输入每人限制"
            controls-position="right" style="width:300px" />
        </el-form-item>
        <el-form-item label="发行数量" prop="publishNum">
          <el-input-number v-model="form.publishNum" placeholder="请输入发行数量" style="width:300px"
            :disabled="disabledStstus" />
        </el-form-item>
        <el-form-item label="已领取数量" prop="receivedNum">
          <el-input-number v-model="form.receivedNum" placeholder="请输入已领取数量" style="width:300px" />
        </el-form-item>
        <el-form-item label="已使用数量" prop="usedNum">
          <el-input-number v-model="form.usedNum" placeholder="请输入已使用数量" style="width:300px" />
        </el-form-item>
        <el-form-item label="类型" prop="couponType">
          <el-radio-group v-model="form.couponType" style="width: 300px;">
            <el-radio v-for="dict in dict.type.coupon_type" :key="dict.value"
              :label="dict.value">{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="面值" prop="price" v-show="form.couponType === 'PRICE'">
          <el-input-number v-model="form.price" placeholder="请输入面值" style="width:300px" />
        </el-form-item>
        <el-form-item label="折扣" prop="couponDiscount" v-show="form.couponType === 'DISCOUNT'">
          <el-input-number v-model="form.couponDiscount" placeholder="请输入折扣率" style="width:300px" />
        </el-form-item>
        <el-form-item label="优惠上限" prop="maxPrice" v-show="form.couponType === 'DISCOUNT'">
          <el-input-number v-model="form.maxPrice" placeholder="请输入最高优惠金额" style="width:300px" />
        </el-form-item>
        <el-form-item label="活动描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入活动描述" type="textarea"
            style="width:300px" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加促销范围里面的指定商品对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="title"
      :visible.sync="openAlert" width="800px" append-to-body v-loading="loading">
      <el-form :model="queryParam" ref="queryForms" size="small" :inline="true" v-show="showSearch">
        <el-col :span="12">
          <el-form-item label="商品名称" prop="goodsName">
            <el-input v-model="queryParam.goodsName" placeholder="请输入商品名称" clearable
              style="width: 240px" @keyup.enter.native="handleQuerys" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品id" prop="id">
            <el-input v-model="queryParam.id" placeholder="请输入商品id" clearable style="width: 240px"
              @keyup.enter.native="handleQuerys" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品编号" prop="identifier">
            <el-input v-model="queryParam.identifier" placeholder="请输入商品编号" clearable
              style="width: 240px" @keyup.enter.native="handleQuerys" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuerys">搜索
            </el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuerys">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
      <el-table :data="goodsSkuLists" :row-key="getRowKeys"
        @selection-change="handleSelectionChanges">
        <el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
        <el-table-column label="商品名称" prop="goodsName" width="200" align="center" />
        <el-table-column label="商品编码" prop="identifier" width="100" align="center" />
        <el-table-column label="商品条码" prop="barCode" width="200" align="center" />
        <el-table-column label="商品id" prop="id" width="200" align="center" />
      </el-table>
      <pagination v-show="totals>0" :total="totals" :page.sync="queryParam.pageNum"
        :limit.sync="queryParam.pageSize" @pagination="getLists" />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForms">确 定</el-button>
        <el-button @click="cancels">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 分配角色数据权限对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="title"
      :visible.sync="openDataScope" width="500px" append-to-body>
      <el-form :model="form" label-width="80px">
        <el-form-item label="角色名称">
          <el-input v-model="form.roleName" :disabled="true" />
        </el-form-item>
        <el-form-item label="权限字符">
          <el-input v-model="form.roleKey" :disabled="true" />
        </el-form-item>
        <el-form-item label="权限范围">
          <el-select v-model="form.dataScope" @change="dataScopeSelectChange">
            <el-option v-for="item in dataScopeOptions" :key="item.value" :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据权限" v-show="form.dataScope == 2">
          <el-checkbox v-model="deptExpand" @change="handleCheckedTreeExpand($event, 'dept')">展开/折叠
          </el-checkbox>
          <el-checkbox v-model="deptNodeAll" @change="handleCheckedTreeNodeAll($event, 'dept')">
            全选/全不选</el-checkbox>
          <el-checkbox v-model="form.deptCheckStrictly"
            @change="handleCheckedTreeConnect($event, 'dept')">父子联动</el-checkbox>
          <el-tree class="tree-border" :data="deptOptions" show-checkbox default-expand-all
            ref="dept" node-key="id" :check-strictly="!form.deptCheckStrictly" empty-text="加载中，请稍候"
            :props="defaultProps"></el-tree>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDataScope">确 定</el-button>
        <el-button @click="cancelDataScope">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 促销商品导入对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="upload.title"
      :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action=" r+
          '/store/promotion/promotion/BARGAIN/' +
          this.id +
          '/importData' + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false"
            style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 删除优惠券 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="提示" :visible.sync="open1"
      width="400px" append-to-body>
      <span>确认作废吗？</span>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCoupon">确 定</el-button>
        <el-button @click="open1 = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 指定促销商品 导入对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag :title="upload1.title"
      :visible.sync="upload1.open" width="400px" append-to-body>
      <el-upload ref="upload1" :limit="1" accept=".xlsx, .xls" :headers="upload1.headers" :action="r+'/store/promotion/coupon/'+upload1.promotionId+
        '/importData'+'?updateSupport=' + upload1.updateSupport" :disabled="upload1.isUploading"
        :on-progress="handleFileUploadProgress1" :on-success="handleFileSuccess1"
        :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload1.updateSupport" />是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false"
            style="font-size:12px;vertical-align: baseline;" @click="importTemplate1">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm1">确 定</el-button>
        <el-button @click="upload1.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 指定促销商品 导入对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="导入屏蔽商品"
      :visible.sync="excludSkuImport.open" width="400px" append-to-body>
      <el-upload ref="excludSkuImport" :limit="1" accept=".xlsx, .xls"
        :headers="excludSkuImport.headers"
        :action="r+'/store/promotion/coupon/'+excludSkuImport.promotionId+'/exclude/importData'+'?updateSupport=' + excludSkuImport.updateSupport"
        :disabled="excludSkuImport.isUploading" :on-progress="handleFileUploadProgress2"
        :on-success="handleFileSuccess2" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false"
            style="font-size:12px;vertical-align: baseline;" @click="importTemplate1">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitExcludSkuImportFile">确 定</el-button>
        <el-button @click="excludSkuImport.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 商品详情 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="商品详情" :visible.sync="open4"
      width="1200px">
      商品编码: <el-input v-model="preferentialCommodity.identifier" style="width:200px"
        clearable></el-input>
      商品名称: <el-input v-model="preferentialCommodity.goodsName" style="width:200px"
        clearable></el-input>
      <el-button type="danger" @click="getPreferentialCommodityList"
        style="margin:0 0 20px 20px">搜索</el-button>
      <el-button type="primary" plain icon="el-icon-download" size="mini"
        style="margin:0 0 20px 20px" @click="handlePromotionGoodsExport"
        v-hasPermi="['store:promotion:promotion:goods:export']">导出商品</el-button>
      <el-table :data="preferentialCommodityList">
        <el-table-column label="排序" prop="orderNum" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.orderNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="商品编码" prop="identifier" align="center"> </el-table-column>
        <el-table-column label="商品名称" prop="goodsName" align="center" width="300px">
        </el-table-column>
        <el-table-column label="规格" prop="simpleSpecs" align="center"> </el-table-column>
        <el-table-column label="商品原价" prop="originalPrice" align="center"></el-table-column>
        <el-table-column label="活动价" prop="price" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.price"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="销售下限" prop="unitage" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.unitage"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="限购方式" prop="limitMode" align="center" width="130px">
          <template slot-scope="scope">
            <el-select v-model="scope.row.limitMode" placeholder="限购方式">
              <el-option v-for="dict in dict.type.promotion_limit_mode" :key="dict.value"
                :label="dict.label" :value="dict.value" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="限购数量" prop="limitNum" align="center">
          <template slot-scope="scope">
            <el-input v-model="scope.row.limitNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="已购数量" prop="num" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="200px">
          <template slot-scope="scope">
            <el-button size="mini" @click="modifySeckillCommodity(scope.row)">修改</el-button>
            <el-button size="mini" @click="delSeckillCommodity(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="parseInt(preferentialCommodityForm.total) >0"
        :total="parseInt(preferentialCommodityForm.total)"
        :page.sync="preferentialCommodityForm.pageNum"
        :limit.sync="preferentialCommodityForm.pageSize"
        @pagination="getPreferentialCommodityList" />
    </el-dialog>

    <!-- 屏蔽的商品详情 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="屏蔽的商品列表"
      :visible.sync="openExcludeGoodsVisible" width="800px">
      商品编码: <el-input v-model="excludeSkuForm.identifier" style="width:200px" clearable></el-input>
      商品名称: <el-input v-model="excludeSkuForm.goodsName" style="width:200px" clearable></el-input>
      <el-button type="danger" @click="getExcludeSkuList" style="margin:0 0 20px 20px"
        v-hasPermi="['store:promotion:coupon:exclude:sku:page']">搜索</el-button>
      <el-button type="primary" plain icon="el-icon-download" size="mini"
        style="margin:0 0 20px 20px" @click="handleExcludeSkuExport"
        v-hasPermi="['store:promotion:coupon:exclude:sku:export']">导出商品
      </el-button>
      <el-table :data="excludeSkuList">
        <el-table-column label="商品编码" prop="identifier" align="center"> </el-table-column>
        <el-table-column label="商品名称" prop="goodsName" align="center" width="300px">
        </el-table-column>
        <el-table-column label="规格" prop="simpleSpecs" align="center"> </el-table-column>
        <el-table-column label="商品原价" prop="originalPrice" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="200px">
          <template slot-scope="scope">
            <el-button size="mini" @click="modifySeckillCommodity(scope.row)">修改</el-button>
            <el-button size="mini" @click="delSeckillCommodity(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="parseInt(excludeSkuForm.total) >0" :total="parseInt(excludeSkuForm.total)"
        :page.sync="excludeSkuForm.pageNum" :limit.sync="excludeSkuForm.pageSize"
        @pagination="getExcludeSkuList" />
    </el-dialog>

  </div>
</template>

<script>
import {
  listConfig, getRole, delRole, addConfig, updateConfig, dataScope,
  addGoodsSku, updateRoleGoods, changeRoleStatus, deleteConfig, listExcludeSku
} from "@/api/promotion/config"
import { listGoodsSku } from "@/api/goods/goods"
import axios from "axios"
import { getToken } from "@/utils/auth"
import { getPromotionGoodsList, updatePromotionGoods, delPromotionGoods } from "@/api/promotion/promotions.js"

export default {
  name: "CouponConfig",
  dicts: ["coupon_get_type", "coupon_type", "promotion_scope_type", "promotion_promotion_status", "goods_promotion_status"],
  data () {
    return {
      disabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      idss: [],
      alls: [],
      couponNames: "",
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      totals: 0,
      // 角色表格数据
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 确认删除框
      open1: false,
      // 是否显示弹出层 (指定商品)
      openAlert: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      promotionDateRange: [],
      // 日期范围
      dateRange: [],
      id: "",
      r: process.env.VUE_APP_BASE_API,
      // 商品表格数据
      goodsSkuList: [],
      // 商品表格数据
      goodsSkuLists: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() }
        // 上传的地址
        // url:
        //   process.env.VUE_APP_BASE_API +
        //   "/store/promotion/promotion/BARGAIN/" +
        //   this.id +
        //   "/importData"
      },
      // 数据范围选项
      dataScopeOptions: [
        { value: "1", label: "全部数据权限" },
        { value: "2", label: "自定数据权限" },
        { value: "3", label: "本部门数据权限" },
        { value: "4", label: "本部门及以下数据权限" },
        { value: "5", label: "仅本人数据权限" }
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        paramMap:{
          status:'',
          beginStartTime: undefined,
          endEndTime: undefined,
        }
      },
      // 查询参数(指定商品)
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        id: undefined,
        goodsName: undefined,
        identifier: undefined,
        barCode: undefined,
        paramMap:{
          beginStartTime: undefined,
          endEndTime: undefined,
        }
      },
      // 表单参数
      form: {
        consumeQuantity: 0,
        consumeThreshold: 0,
        getType: "FREE",
        scopeType: "ALL",
        couponType: "PRICE",
      },
      defaultProps: {
        children: "children",
        label: "label"
      },
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      imageFileList: undefined,
      headers: {
        Authorization: "Bearer " + getToken(),
        "Content-Type": "multipart/form-data"
      },
      // 表单校验
      rules: {
        promotionName: [
          { required: true, message: "活动名称不能为空", trigger: "blur" }
        ],
        couponName: [
          { required: true, message: "优惠券名称不能为空", trigger: "blur" }
        ],
        getType: [
          { required: true, message: "优惠券获取方式不能为空", trigger: "change" }
        ],
        scopeType: [
          { required: true, message: "促销范围不能为空", trigger: "change" }
        ],
        startTime: [
          { required: true, message: "开始时间不能为空", trigger: "blur" }
        ],
        endTime: [
          { required: true, message: "结束时间不能为空", trigger: "blur" }
        ],
        detailAppImage: [
          { required: true, message: "背景图不能为空", trigger: "blur" }
        ],
      },
      // 列信息
      columns: [
        { key: 0, label: `ID`, prop: "id", width: 170, visible: true },
        { key: 1, label: `活动名称`, prop: "promotionName", width: 150, visible: true },
        { key: 2, label: `优惠券名称`, prop: "couponName", width: 120, visible: true },
        { key: 3, label: `获取方式`, prop: "getType", width: 90, visible: true },
        { key: 4, label: `发行数量`, prop: "publishNum", width: 80, visible: true },
        { key: 5, label: `领取上限`, prop: "couponLimitNum", width: 80, visible: true },
        { key: 6, label: `已领取数量`, prop: "receivedNum", width: 90, visible: false },
        { key: 7, label: `已使用数量`, prop: "usedNum", width: 90, visible: false },
        { key: 8, label: `类型`, prop: "couponType", width: 80, visible: true },
        { key: 9, label: `面值`, prop: "price", width: 70, visible: true },
        { key: 10, label: `折扣率`, prop: "couponDiscount", width: 60, visible: true },
        { key: 11, label: `消费门槛数量`, prop: "consumeQuantity", width: 100, visible: false },
        { key: 12, label: `消费门槛金额`, prop: "consumeThreshold", width: 100, visible: true },
        { key: 13, label: `背景图`, prop: "detailAppImage", width: 100, visible: false },
        { key: 14, label: `活动描述`, prop: "description", width: 200, visible: false },
        { key: 15, label: `开始时间`, prop: "startTime", width: 150, visible: true },
        { key: 16, label: `结束时间`, prop: "endTime", width: 150, visible: true },
        { key: 17, label: `促销范围`, prop: "scopeType", width: 80, visible: true },
        { key: 18, label: `状态`, prop: "promotionStatus", width: 110, visible: true }
      ],
      // 新建  修改    部分 禁用状态  disabled
      disabledStstus: false,
      getRowKeys (row) {
        return row.goodsId;
      },
      salesPromotionSync: false,
      upload1: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        promotionId: '',
      },
      open4: false,
      preferentialCommodity: {},
      preferentialCommodityList: [],
      preferentialCommodityForm: {},
      ROWS: '',
      excludSkuImport: {
        open: false,
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() }
      },
      openExcludeGoodsVisible: false,
      excludeCouponRow: undefined,
      excludeSkuList: [],
      excludeSkuForm: {
        goodsName: undefined,
        identifier: undefined,
      },
    }
  },
  created () {
    this.getList();
  },
  methods: {
    openSeeSalesGoodsView (row) {
      this.ROWS = row
      this.getPreferentialCommodityList()
      this.open4 = true
    },
    getPreferentialCommodityList () {
      getPromotionGoodsList(this.ROWS.id, { promotionType: 'COUPON', ...(this.preferentialCommodityForm) }).then(res => {
        if (res.code === 200) {
          this.preferentialCommodityList = res.rows
          this.preferentialCommodityForm.total = res.total
        }
      })
    },

    handlePromotionGoodsExport () {
      this.download('store/promotion/promotion/' + this.ROWS.id + '/export?promotionType=COUPON&identifier=' + this.preferentialCommodityForm.identifier + '&goodsName=' + this.preferentialCommodityForm.goodsName, {
        ...this.addDateRangeWithMap(this.addDateRangeWithMap(this.queryParams, this.dateRange, "CreateTime"), this.payDateRange, "PaymentTime")
      }, `优惠券商品列表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}{i}{s}")}.xlsx`)
    },

    modifySeckillCommodity (row) {
      let that = this
      this.$modal.confirm('是否确认修改？').then(function () {
        return updatePromotionGoods('COUPON', that.ROWS.id, row.id, { price: row.price, orderNum: row.orderNum, limitMode: row.limitMode, limitNum: row.limitNum, unitage: row.unitage })
      }).then(() => {
        this.$modal.msgSuccess("修改成功");
        this.getPreferentialCommodityList()
      }).catch(() => {
        this.$modal.msgError("修改失败");
      })
    },
    delSeckillCommodity (row) {
      let that = this
      this.$modal.confirm('是否确认删除？').then(function () {
        return delPromotionGoods('COUPON', that.ROWS.id, row.id)
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
        this.getPreferentialCommodityList()
      }).catch(() => {
        this.$modal.msgError("删除失败");
      })
    },
    openImportSalesPromotionView (row) {
      this.upload1.promotionId = row.id
      this.upload1.title = '导入促销商品'
      this.upload1.open = true
    },
    importTemplate1 () {
      this.download(
        "store/promotion/coupon/goods/importTemplate", {}, `coupon_template_${new Date().getTime()}.xlsx`
      )
    },
    submitFileForm1 () {
      this.$refs.upload1.submit()
    },
    submitExcludSkuImportFile () {
      this.$refs.excludSkuImport.submit()
    },
    handleFileUploadProgress1 (event, file, fileList) {
      this.upload1.isUploading = true
    },
    handleFileSuccess1 (response, file, fileList) {
      this.upload1.open = false
      this.upload1.isUploading = false
      this.$refs.upload1.clearFiles()
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
    },
    handleFileUploadProgress2 (event, file, fileList) {
      this.excludSkuImport.isUploading = true
    },
    handleFileSuccess2 (response, file, fileList) {
      this.excludSkuImport.open = false
      this.excludSkuImport.isUploading = false
      this.$refs.excludSkuImport.clearFiles()
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
    },

    /** 查询角色列表 */
    getList () {
      this.loading = true;
      this.queryParams.paramMap.beginStartTime = ''
      this.queryParams.paramMap.endEndTime = ''
      if(this.promotionDateRange && this.promotionDateRange.length > 0){
        this.queryParams.paramMap.beginStartTime = this.promotionDateRange[0]
        this.queryParams.paramMap.endEndTime = this.promotionDateRange[1]
      }
      listConfig(this.addDateRangeWithMap(this.queryParams, this.dateRange, "CreateTime")).then(response => {
        this.goodsSkuList = response.rows;
        //获取商品分类名称
        this.goodsSkuList.forEach(goodsSku => {
          let categoryId = goodsSku.categoryPath;
          if (categoryId) {
            let firstIndex = categoryId.lastIndexOf(",");
            if (firstIndex > 0) {
              categoryId = categoryId.substr(firstIndex + 1);
            }
            for (let category of this.categoryOptions) {
              if (category.id == categoryId) {
                goodsSku.categoryName = category.name;
                break;
              }
            }
          }
        });
        this.total = response.total;
        console.log(this.total);
        this.loading = false;
      });
    },
    /** 查询菜单树结构 */
    getMenuTreeselect () {
      menuTreeselect().then(response => {
        this.menuOptions = response.data;
      });
    },
    /** 查询部门树结构 */
    getDeptTreeselect () {
      deptTreeselect().then(response => {
        this.deptOptions = response.data;
      });
    },

    // 所有部门节点数据
    getDeptAllCheckedKeys () {
      // 目前被选中的部门节点
      let checkedKeys = this.$refs.dept.getCheckedKeys();
      // 半选中的部门节点
      let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    /** 根据角色ID查询菜单树结构 */
    getRoleMenuTreeselect (roleId) {
      return roleMenuTreeselect(roleId).then(response => {
        this.menuOptions = response.menus;
        return response;
      });
    },
    /** 根据角色ID查询部门树结构 */
    getRoleDeptTreeselect (roleId) {
      return roleDeptTreeselect(roleId).then(response => {
        this.deptOptions = response.depts;
        return response;
      });
    },

    // 取消按钮
    cancel () {
      this.open = false;
      // this.reset();
    },
    // 取消按钮(指定商品)
    cancels () {
      this.openAlert = false;
      // this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope () {
      this.openDataScope = false;
      // this.reset();
    },
    // 表单重置
    reset () {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      this.menuExpand = false
      this.menuNodeAll = false
      this.deptExpand = true
      this.deptNodeAll = false
      this.form = {
        roleId: undefined,
        roleName: undefined,
        roleKey: undefined,
        roleSort: 0,
        status: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.promotionDateRange = []
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作(指定商品) */
    handleQuerys () {
      this.queryParam.pageNum = 1;
      this.getLists();
    },
    /** 重置按钮操作(指定商品)  */
    resetQuerys () {
      this.dateRange = [];
      this.resetForm("queryForms");
      this.handleQuerys();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.roleId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 多选框选中数据(指定商品)
    handleSelectionChanges (selection) {
      this.alls = selection
      console.log(this.alls)
    },
    // 更多操作触发
    handleCommand (command, row) {
      switch (command) {
        case "handleUpdate":
          this.handleUpdate(row)
          break;
        case "handleImportGoods":
          this.openImportSalesPromotionView(row);
          break;
        case "handleSeeSalesGoods":
          this.openSeeSalesGoodsView(row);
          break;
        case "handleImportExcludeGoods":
          this.handleImportExcludeGoods(row);
          break;
        case "handleExcludeGoods":
          this.openExcludeGoodsView(row);
          break;
        default:
          break;
      }
    },
    handleImportExcludeGoods (row) {
      this.excludSkuImport.promotionId = row.id
      this.excludSkuImport.open = true
    },
    openExcludeGoodsView (row) {
      this.excludeCouponRow = row
      this.getExcludeSkuList()
    },
    getExcludeSkuList () {
      if (this.excludeSkuForm.identifier) {
        this.excludeSkuForm.identifier = this.excludeSkuForm.identifier.trim().toUpperCase()
      }
      if (this.excludeSkuForm.goodsName) {
        this.excludeSkuForm.goodsName = this.excludeSkuForm.goodsName.trim()
      }

      listExcludeSku(this.excludeCouponRow.id, this.excludeSkuForm).then(response => {
        this.excludeSkuList = response.rows
        this.excludeSkuForm.total = response.total
        this.openExcludeGoodsVisible = true
      })
    },
    handleExcludeSkuExport () {
      if (this.excludeSkuForm.identifier) {
        this.excludeSkuForm.identifier = this.excludeSkuForm.identifier.trim().toUpperCase()
      }
      if (this.excludeSkuForm.goodsName) {
        this.excludeSkuForm.goodsName = this.excludeSkuForm.goodsName.trim()
      }

      this.download('store/promotion/coupon/' + this.excludeCouponRow.id + '/exclude/skus/export', {
        identifier: this.excludeSkuForm.identifier,
        goodsName: this.excludeSkuForm.goodsName
      }, `优惠券屏蔽商品列表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}{i}{s}")}.xlsx`)
    },
    // 树权限（展开/折叠）
    handleCheckedTreeExpand (value, type) {
      if (type == "menu") {
        let treeList = this.menuOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
        }
      } else if (type == "dept") {
        let treeList = this.deptOptions;
        for (let i = 0; i < treeList.length; i++) {
          this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
        }
      }
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.form.getType = "DISTRIBUTE"
      this.form.scopeType = "ALL"
      //this.form.startTime = this.parseTime(new Date().getTime(), "{y}-{m}-{d} {h}:{i}:{s}")
      this.form.publishNum = 10000
      this.form.consumeThreshold = 999
      this.form.couponLimitNum = 3
      this.form.receivedNum = 0
      this.form.usedNum = 0
      this.form.couponType = "PRICE"
      this.disabledStstus = false

      this.open = true;
      this.title = "创建优惠券";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.disabledStstus = true
      this.form = row;
      this.open = true;
      this.title = "修改优惠券";
    },
    // 作废
    toVoid (row) {
      this.row = row
      this.open1 = true
    },
    submitCoupon () {
      deleteConfig(this.row.id).then(res => {
        if (res.code === 200) {
          this.open1 = false
          this.getList()
        }
      })
    },

    // 上传商品
    Uploadproduct (row) {
      this.upload.title = "优惠券导入";
      this.upload.open = true;
      this.id = row.id;
    },
    /** 选择角色权限范围触发 */
    dataScopeSelectChange (value) {
      if (value !== "2") {
        this.$refs.dept.setCheckedKeys([]);
      }
    },
    /** 分配数据权限操作 */
    handleDataScope (row) {
      this.reset();
      const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
      getRole(row.roleId).then(response => {
        this.form = response.data;
        this.openDataScope = true;
        this.$nextTick(() => {
          roleDeptTreeselect.then(res => {
            this.$refs.dept.setCheckedKeys(res.checkedKeys);
          });
        });
        this.title = "分配数据权限";
      });
    },
    /** 分配用户操作 */
    handleAuthUser: function (row) {
      const roleId = row.roleId;
      this.$router.push("/system/role-auth/user/" + roleId);
    },
    /** 提交按钮 */
    submitForm: function () {
      if (!this.form.couponLimitNum || this.form.couponLimitNum < 1) {
        this.$message.error("领取上限必须大于0");
        return;
      }
      if (!this.form.publishNum || this.form.publishNum <= 0) {
        this.$message.error("发行数量必须大于0");
        return;
      }
      if ('DISCOUNT' === this.form.couponType) {
        this.form.price = 0
        if (!this.form.couponDiscount) {
          this.$message.error("请输入折扣值");
          return;
        }

        if (this.form.couponDiscount) {
          if (this.form.couponDiscount <= 0) {
            this.$message.error("折扣必须大于0");
            return;
          } else if (this.form.couponDiscount >= 1) {
            this.$message.error("折扣必须小于1");
            return;
          }
        }
        if (!this.form.maxPrice && this.form.maxPrice > 0) {
          this.form.price = this.form.maxPrice
        }
      } else {
        this.form.couponDiscount = 0
        if (!this.form.price) {
          this.$message.error("请输入面值");
          return;
        }
        if (this.form.price <= 0) {
          this.$message.error("面值必须大于0");
          return;
        }
      }

      if (this.form.consumeQuantity == undefined) {
        this.$message.error("请输入消费门槛金额");
        return;
      }
      if (this.form.consumeQuantity <= 0) {
        if (this.form.price) {
          if (this.form.consumeThreshold < this.form.price) {
            this.$message.error("消费门槛金额必须大于面值");
            return;
          }
        }
      }

      if (this.title === "创建优惠券") {
        addConfig(this.form).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("新增成功")
            this.open = false;
            this.getList();
          }
        })
      }
      if (this.title === "修改优惠券") {
        updateConfig(this.form).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("修改成功")
            this.open = false;
            this.getList()
          }
        })
      }
    },
    /** 提交按钮（指定商品） */
    submitForms: function () {
      // for (var i = 0; i < this.alls.length; i++) {
      // }
      // this.couponNames = this.alls;
      this.openAlert = false;
      this.title = "添加优惠券"
    },
    /** 提交按钮（数据权限） */
    submitDataScope: function () {
      if (this.form.roleId != undefined) {
        this.form.deptIds = this.getDeptAllCheckedKeys();
        dataScope(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.openDataScope = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const roleIds = row.roleId || this.ids;
      this.$modal.confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？').then(function () {
        return delRole(roleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 下载模板操作 */
    importTemplate () {
      this.download(
        "store/promotion/promotion/goods/importTemplate",
        {},
        `bargain_template_${new Date().getTime()}.xlsx`
      );
    },
    // 提交上传文件
    submitFileForm () {
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress (event, file, fileList) {
      this.upload.isUploading = true;
      console.log("event", event);
    },
    // 文件上传成功处理
    handleFileSuccess (response, file, fileList) {
      console.log("response", response);
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    /** 导入按钮操作 */
    handleImport () {
      this.upload.title = "优惠券导入";
      this.upload.open = true;
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        "store/promotion/promotion/goods/importTemplate",
        {
          ...this.queryParams
        },
        `bargain_template_${new Date().getTime()}.xlsx`
      );
    },
    // 删除图片
    handleRemove (file, fileList) {
      const ul = document.querySelector(".el-upload-list--picture-card");
      ul.removeChild(ul.children[0]);
      ul.nextSibling.style.display = "block";
      console.log(file, fileList);
    },
    // 预览图片
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.raw.url;
      this.dialogVisible = true;
    },
    //   上传图片
    changeImg (file, fileList) {
      const ul = document.querySelector(".el-upload-list--picture-card");
      ul.nextSibling.style.display = "none";
      console.log(file, fileList);
      this.imageFileList = fileList;
    },
    // 每次清除input框之后赋值为0
    blurNumber (e, name) {
      if (!e.target.value) {
        this.form[name] = 0;
      }
    },
    scopeType () {
      // 促销范围为指定商品
      if (this.form.scopeType == "PORTION_GOODS") {
        // this.openAlert = true;
        // this.title = "添加指定商品";
        // this.getLists();
        // document.querySelector(".couponName").style.display = "block";
        // console.log(this.couponNames);
      }
      // 促销范围为全品类
      if (this.form.scopeType == "ALL") {
        // document.querySelector(".couponName").style.display = "none";
        // document.getElementById("ipt").value = "";
        // this.couponNames = "";
        // console.log(this.couponNames);
      }
    },
    /** 查询角色列表 */
    getLists () {
      // this.loading = true;
      listGoodsSku(0, this.addDateRangeWithMap(this.queryParam, this.dateRange, "CreateTime")).then(response => {
        this.goodsSkuLists = response.rows
        //获取商品分类名称
        // this.goodsSkuLists.forEach(goodsSkus => {
        //   let categoryIds = goodsSkus.categoryPath
        //   if (categoryIds) {
        //     let firstIndex = categoryIds.lastIndexOf(",")
        //     if (firstIndex > 0) {
        //       categoryIds = categoryIds.substr(firstIndex + 1)
        //     }
        //     for (let category of this.categoryOptions) {
        //       if (category.id == categoryIds) {
        //         goodsSkus.categoryName = category.name
        //         break
        //       }
        //     }
        //   }
        // })
        this.totals = response.total
        this.loading = false
      })
    },
  }
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  top: 0;
}
</style>
